package leetcode;

public class ContainerWithMostWater {

    public static void main(String[] args) {
        ContainerWithMostWater c = new ContainerWithMostWater();
        int i = c.maxArea(new int[]{1, 8, 6, 2, 5, 4, 8, 3, 7});
        System.out.println(i);
    }

    public int maxArea(int[] height) {
        int max = 0;
        int j = 0;
        int i = height.length - 1;
        while(j < height.length && i > j){
            int cur = 0;
            if(height[j] <= height[i]){
                cur = height[j] * (i - j);
                j++;
            }else{
                cur = height[i] * (i - j);
                i --;
            }
            max = Math.max(max, cur);
        }
        return max;
    }


    public int maxAreaForce(int[] height) {
        int max = 0;
        int j = 0;
        while(j < height.length){
            int i = height.length - 1;
            while(i > j){
                int cur = 0;
                if(height[j] <= height[i]){
                    cur = height[j] * (i - j);
                }else{
                    cur = height[i] * (i - j);
                }
                max = Math.max(max, cur);
                i --;
            }
            j ++;
        }

        return max;
    }

}
